<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
<!-- View -->
<p id="oP"></p>
<input type="text" id="oInput">
<script>
// Model
const data = {
  str: 'hello'
}
const copyData = { ...data }

// Model => View 是通过 Data Bindings 做到的
Object.defineProperty(data, 'str',  {
  get() {
    // 获取数据的时候会自动触发这儿
    return copyData.str
  },
  set(newValue) {
    // #1
    copyData.str = newValue
    oP.innerHTML = newValue
    oInput.value = newValue
  }
})
// View => Model 是通过 DOM Listeners 做到的
oInput.oninput = function(e) {
  // 边输入，边把输入的内容给 data.str
  // 一旦对 data.str 赋值，就会触发 #1 处的代码
  data.str = e.target.value
}
</script>
</body>
</html>